home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / GBlanker / GSource / MUI / interface.c next >
C/C++ Source or Header  |  1996-09-26  |  8KB  |  260 lines

  1. #include <exec/memory.h>
  2. #include <dos/dostags.h>
  3. #include <libraries/mui.h>
  4. #include <string.h>
  5.  
  6. #include <clib/muimaster_protos.h>
  7. #include <pragmas/muimaster_pragmas.h>
  8.  
  9. #include <clib/wb_protos.h>
  10. #include <pragmas/wb_pragmas.h>
  11.  
  12. #include "interface.h"
  13. #include "/includes.h"
  14. #include "/libraries.h"
  15. #include "/protos/protos.h"
  16.  
  17. #define MAKE_ID(a,b,c,d)\
  18. ((ULONG)(a)<<24|(ULONG)(b)<<16|(ULONG)(c)<<8|(ULONG)(d))
  19.  
  20. Object *BlankersLvw, *PrefsBtn, *InfoBtn, *ToggleBtn, *HideBtn;
  21. Object *SettingsBtn, *QuitBtn, *BlankWnd, *BlankApp;
  22. struct Library *MUIMasterBase = 0L;
  23. ULONG MUI_Sigs = 0L;
  24. BYTE Title[128];
  25.  
  26. STRPTR SettingsFmt = "BLANKKEY=%s\nPOPKEY=%s\nTIMEOUT=%ld\nREPLACE=%s\n"
  27.     "RANDTIMEOUT=%ld\nBLANKCORNER=%s\nDONTCORNER=%s";
  28.  
  29. __saveds __asm APTR EntryConsFunc( register __a0 struct Hook *Hook,
  30.     register __a1 BlankerEntry *Entry )
  31. {
  32.     return Entry;
  33. }
  34. struct Hook EntryConsHook = {{ 0L, 0L }, ( APTR )EntryConsFunc, 0L, 0L };
  35.  
  36. __saveds __asm VOID EntryDestFunc( register __a0 struct Hook *Hook,
  37.     register __a1 BlankerEntry *Entry )
  38. {
  39. }
  40. struct Hook EntryDestHook = {{ 0L, 0L }, ( APTR )EntryDestFunc, 0L, 0L };
  41.  
  42. __saveds __asm LONG EntryDispFunc( register __a0 struct Hook *Hook,
  43.     register __a1 BlankerEntry *Entry, register __a2 BYTE **Array )
  44. {
  45.     static BYTE Buffer[64];
  46.  
  47.     if( Entry->be_Disabled )
  48.     {
  49.         strcpy( Buffer, "(" );
  50.         strcat( Buffer, Entry->be_Name );
  51.         strcat( Buffer, ")" );
  52.     }
  53.     else
  54.         strcpy( Buffer, Entry->be_Name );
  55.  
  56.     *Array = Buffer;
  57.  
  58.     return 0L;
  59. }
  60. struct Hook EntryDispHook = {{ 0L, 0L }, ( APTR )EntryDispFunc, 0L, 0L };
  61.  
  62. ULONG ISigs( VOID )
  63. {
  64.     return MUI_Sigs;
  65. }
  66.  
  67. LONG OpenInterface( VOID )
  68. {
  69.     if( MUIMasterBase )
  70.         return OK;
  71.  
  72.     if(!( MUIMasterBase = OpenLibrary( MUIMASTER_NAME, MUIMASTER_VMIN )))
  73.         return QUIT;
  74.  
  75.     strcpy( Title, "Garshneblanker ( PopKey=" );
  76.     strcat( Title, Prefs->bp_PopKey );
  77.     strcat( Title, ", BlankKey=" );
  78.     strcat( Title, Prefs->bp_BlankKey );
  79.     strcat( Title, " )" );
  80.  
  81.     BlankWnd = WindowObject,
  82.         MUIA_Window_ID, MAKE_ID( 'M', 'A', 'I', 'N' ),
  83.         MUIA_Window_ScreenTitle, Title,
  84.         MUIA_Window_Title, FilePart( ProgName ),
  85.         MUIA_Window_RootObject, VGroup,
  86.             Child,
  87.                 BlankersLvw = ListviewObject,
  88.                     MUIA_Listview_List, ListObject,
  89.                         MUIA_Frame, MUIV_Frame_InputList,
  90.                         MUIA_List_ConstructHook, &EntryConsHook,
  91.                         MUIA_List_DestructHook, &EntryDestHook,
  92.                         MUIA_List_DisplayHook, &EntryDispHook,
  93.                     End,
  94.                 End,
  95.             Child,
  96.                 HGroup,
  97.                     Child, PrefsBtn = KeyButton( "Prefs", 'p' ),
  98.                     Child, InfoBtn = KeyButton( "Info", 'i' ),
  99.                     Child, ToggleBtn = KeyButton( "Toggle", 't' ),
  100.                 End,
  101.             Child,
  102.                 HGroup,
  103.                     Child, HideBtn = KeyButton( "Hide", 'h' ),
  104.                     Child, SettingsBtn = KeyButton( "Settings", 's' ),
  105.                     Child, QuitBtn = KeyButton( "Quit", 'q' ),
  106.                 End,
  107.         End,
  108.     End;
  109.  
  110.     BlankApp = ApplicationObject,
  111.         MUIA_Application_Title, "Garshneblanker",
  112.         MUIA_Application_Version, VERS,
  113.         MUIA_Application_Copyright, "Free Software",
  114.         MUIA_Application_Author, "Michael D. Bayne",
  115.         MUIA_Application_Description, "Screen blanker",
  116.         MUIA_Application_Base, "GBLANKER",
  117.         MUIA_Application_Window, BlankWnd,
  118.     End;
  119.  
  120.     if( BlankApp )
  121.     {
  122.         BlankerEntry *Tmp;
  123.         LONG i, Selected, Rand;
  124.         
  125. #ifdef FUNKY_MUI
  126.         DoMethod( BlankApp, MUIM_Application_Load,
  127.             MUIV_Application_Load_ENVARC );
  128. #endif
  129.         DoMethod( BlankWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  130.             BlankApp, 2, MUIM_Application_ReturnID, ID_HIDE );
  131.         DoMethod( BlankersLvw, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  132.             BlankApp, 2, MUIM_Application_ReturnID, ID_BLANKERS );
  133.         DoMethod( BlankersLvw, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  134.             BlankApp, 2, MUIM_Application_ReturnID, ID_PREFS );
  135.         DoMethod( PrefsBtn, MUIM_Notify, MUIA_Pressed, FALSE, BlankApp, 2,
  136.             MUIM_Application_ReturnID, ID_PREFS );
  137.         DoMethod( InfoBtn, MUIM_Notify, MUIA_Pressed, FALSE, BlankApp, 2,
  138.             MUIM_Application_ReturnID, ID_INFO );
  139.         DoMethod( ToggleBtn, MUIM_Notify, MUIA_Pressed, FALSE, BlankApp, 2,
  140.             MUIM_Application_ReturnID, ID_TOGGLE );
  141.         DoMethod( HideBtn, MUIM_Notify, MUIA_Pressed, FALSE, BlankApp, 2,
  142.             MUIM_Application_ReturnID, ID_HIDE );
  143.         DoMethod( SettingsBtn, MUIM_Notify, MUIA_Pressed, FALSE, BlankApp, 2,
  144.             MUIM_Application_ReturnID, ID_SET );
  145.         DoMethod( QuitBtn, MUIM_Notify, MUIA_Pressed, FALSE, BlankApp, 2,
  146.             MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );
  147.         DoMethod( BlankWnd, MUIM_Window_SetCycleChain, BlankersLvw, PrefsBtn,
  148.             InfoBtn, ToggleBtn, HideBtn, SettingsBtn, QuitBtn, 0L );
  149.         for( i = 0, Tmp = ( BlankerEntry * )BlankerEntries->lh_Head;
  150.             Tmp->be_Node.ln_Succ;
  151.             i++, Tmp = ( BlankerEntry * )Tmp->be_Node.ln_Succ )
  152.         {
  153.             if( !Stricmp( Tmp->be_Name, Prefs->bp_Blanker ))
  154.                 Selected = i;
  155.             DoMethod( BlankersLvw, MUIM_List_InsertSingle, Tmp,
  156.                 MUIV_List_Insert_Bottom );
  157.         }
  158.         SetAttrs( BlankersLvw, MUIA_List_Active, Selected, TAG_DONE );
  159.         Rand = !Stricmp( Prefs->bp_Blanker, "Random" );
  160.         SetAttrs( PrefsBtn, MUIA_Disabled, Rand, TAG_END );
  161.         SetAttrs( ToggleBtn, MUIA_Disabled, Rand, TAG_END );
  162.         SetAttrs( BlankWnd, MUIA_Window_Open, TRUE, TAG_DONE );
  163.         DoMethod( BlankersLvw, MUIM_List_Jump, Selected );
  164.  
  165.         return HandleInterface();
  166.     }
  167.  
  168.     if( MUIMasterBase )
  169.         CloseLibrary( MUIMasterBase );
  170.  
  171.     return QUIT;
  172. }
  173.  
  174. VOID CloseInterface( VOID )
  175. {
  176. #ifdef FUNKY_MUI
  177.     DoMethod( BlankApp, MUIM_Application_Save,
  178.         MUIV_Application_Save_ENVARC );
  179. #endif
  180.     MUI_Sigs = 0L;
  181.     DisposeObject( BlankApp );
  182.     BlankApp = 0L;
  183.     CloseLibrary( MUIMasterBase );
  184.     MUIMasterBase = 0L;
  185. }
  186.  
  187. LONG HandleInterface( VOID )
  188. {
  189.     BlankerEntry *Entry;
  190.     LONG Rand, RetVal = OK;
  191.  
  192.     if( !MUIMasterBase )
  193.         return OK;
  194.  
  195.     do
  196.     {
  197.         switch( DoMethod( BlankApp, MUIM_Application_Input, &MUI_Sigs ))
  198.         {
  199.         case MUIV_Application_ReturnID_Quit:
  200.             RetVal = QUIT;
  201.             break;
  202.         case ID_HIDE:
  203.             RetVal = CLOSEWIN;
  204.             break;
  205.         case ID_SET:
  206.             if( WBenchMsg )
  207.             {
  208.                 struct Library *WorkbenchBase;
  209.                 
  210.                 if( WorkbenchBase = OpenLibrary( "workbench.library", 39L ))
  211.                 {
  212.                     struct Screen *PubScr;
  213.                     
  214.                     if( PubScr = LockPubScreen( 0L ))
  215.                     {
  216.                         WBInfo( WBenchMsg->sm_ArgList->wa_Lock,
  217.                                WBenchMsg->sm_ArgList->wa_Name, PubScr );
  218.                         UnlockPubScreen( 0L, PubScr );
  219.                         RetVal = RESTART;
  220.                     }
  221.                     CloseLibrary( WorkbenchBase );
  222.                 }
  223.             }
  224.             break;
  225.         case ID_TOGGLE:
  226.             DoMethod( BlankersLvw, MUIM_List_GetEntry,
  227.                      MUIV_List_GetEntry_Active, &Entry );
  228.             ToggleModuleDisabled( Prefs );
  229.             Entry->be_Disabled = !Entry->be_Disabled;
  230.             DoMethod( BlankersLvw, MUIM_List_Redraw, MUIV_List_Redraw_Active );
  231.             break;
  232.         case ID_PREFS:
  233.             if( Stricmp( Prefs->bp_Blanker, "Random" ))
  234.                 ExecSubProc( "PrefInterp", "" );
  235.             break;
  236.         case ID_INFO:
  237.             ExecSubProc( "ShowInfo", ".txt" );
  238.             break;
  239.         case ID_BLANKERS:
  240.             MessageModule( "GarshneClient", BM_DOQUIT );
  241.             MessageModule( "GarshnePrefs", BM_DOQUIT );
  242.             DoMethod( BlankersLvw, MUIM_List_GetEntry,
  243.                      MUIV_List_GetEntry_Active, &Entry );
  244.             strcpy( Prefs->bp_Blanker, Entry->be_Name );
  245.             if( Stricmp( Prefs->bp_Blanker, "Random" ))
  246.                 LoadModule( Prefs->bp_Dir, Prefs->bp_Blanker );
  247.             BlankerToEnv( Prefs );
  248.             Rand = !Stricmp( Prefs->bp_Blanker, "Random" );
  249.             SetAttrs( PrefsBtn, MUIA_Disabled, Rand, TAG_END );
  250.             SetAttrs( ToggleBtn, MUIA_Disabled, Rand, TAG_END );
  251.             break;
  252.         default:
  253.             break;
  254.         }
  255.     }
  256.     while(( RetVal == OK )&& !MUI_Sigs );
  257.  
  258.     return RetVal;
  259. }
  260.